import 'package:enjoy_plus/pages/home/components/home_list.dart';
import 'package:enjoy_plus/pages/home/components/home_nav.dart';
import 'package:enjoy_plus/utils/http.dart';
import 'package:flutter/material.dart';

import '../../utils/toast.dart';

class HomePage extends StatefulWidget {
  const HomePage({super.key});

  @override
  State<HomePage> createState() => _HomePageState();
}

class _HomePageState extends State<HomePage> {
  @override
  void initState() {
    super.initState();
    getNotifyListData();
  }

  List notifyList = [];

  getNotifyListData() async {
    final res = await http.get('/announcement');
    ToastUtil.showInfo('数据加载成功');
    setState(() {
      notifyList = res['data'];
    });
  }

  @override
  Widget build(BuildContext context) {
    return Scaffold(
      backgroundColor: const Color.fromARGB(255, 229, 231, 241),
      appBar: AppBar(
        title: const Text('享+社区'), // 标题文字
        centerTitle: true, // 标题居中
        backgroundColor: Colors.transparent, // 背景透明
      ),
      body: ListView(
        padding: const EdgeInsets.all(10),
        children: [
          // 导航
          HomeNav(),
          // 公告图
          ClipRRect(
            // ClipRRect 圆角矩形裁切组件
            borderRadius: BorderRadius.circular(10),
            child: Image.asset('assets/images/banner@2x.jpg'),
          ),
          const SizedBox(height: 10),
          // 公告列表
          HomeList(notifyList: notifyList),
        ],
      ),
    );
  }
}
